package org.tio.sitexxx.im.server.handler;

import org.tio.core.ChannelContext;
import org.tio.sitexxx.im.common.Command;
import org.tio.sitexxx.im.common.CommandHandler;
import org.tio.sitexxx.im.common.ImPacket;

import org.tio.sitexxx.im.common.MsgModel.KFReadNty;
import org.tio.sitexxx.im.common.MsgModel.KFReadReq;
import org.tio.sitexxx.im.server.Ims;
import org.tio.sitexxx.service.model.main.ChatRecordP2p;
import org.tio.utils.json.Json;

@CommandHandler(Command.KF_P2P_READ_REQ)
public class KFReadHandler implements ImServerHandler {
    @Override
    public void handler(ImPacket packet, ChannelContext channelContext, boolean isWebsocket) throws Exception {
        System.out.println("read");
        KFReadReq req = Json.toBean(packet.getBodyStr(),KFReadReq.class);
        ChatRecordP2p msg = ChatRecordP2p.dao.findFirst("select * from chat_record_p2p where id = ?",req.getCid());
        if(msg!=null){
            msg.setReadflag((byte)1);
            boolean success = msg.update();
            KFReadNty nty = new KFReadNty(success);
            ImPacket imPacket = new ImPacket(Command.KF_P2P_READ_NTY,nty);
            System.out.println(req.getToId()+""+success);
            Ims.sendToUser(req.getToId(),imPacket);
        }
    }
}
